package cn.simon.service;

import cn.simon.mapper.GoodsClassifySecMapper;

import cn.simon.model.GoodsClassifySec;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Kinfer
 * @date 2022/10/24
 */
@Log
@Service
public class GoodsClassifySecService {
    // 二级分类状态：删除
    private static final Integer STATE_ZERO = 0;
    // 二级分类状态：发布
    private static final Integer STATE_ONE = 1;
    @Autowired
    private GoodsClassifySecMapper goodsClassifySecMapper;

    /**
     * 查询一级分类下所有商品二级分类
     *
     * @return goodsClassifySecList
     * @author Kinfer
     * @date 2022/10/24
     */
    public List<GoodsClassifySec> getAllGoodsClassifySec(Integer classifyId) {
        QueryWrapper<GoodsClassifySec> wrapper = new QueryWrapper<>();
        wrapper.eq("classify_sec_state", STATE_ONE);
        if (classifyId != null) {
            wrapper.eq("classify_id", classifyId);
        }

        List<GoodsClassifySec> goodsClassifySecList = goodsClassifySecMapper.selectList(wrapper);

        return goodsClassifySecList;

    }
    public List<GoodsClassifySec> findSecById(Integer id) {

        List<GoodsClassifySec> classifySec = goodsClassifySecMapper.findById(id);
        return classifySec;
    }

    public int addClassifySec(GoodsClassifySec goodsClassifySec) {
        return goodsClassifySecMapper.addByClassifyId(goodsClassifySec);

    }

    public GoodsClassifySec findById(Integer id) {
        return goodsClassifySecMapper.selectById(id);
    }

    public int updateClassifySec(GoodsClassifySec goodsClassifySec) {
        return goodsClassifySecMapper.updateById(goodsClassifySec);
    }

    public int deleteClassifySec(Integer id) {
        return goodsClassifySecMapper.deleteById(id);

    }
}
